<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>#(user.name)</legend>
</fieldset>

<form class="layui-form layui-form-pane" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">ID</label>
        <div class="layui-input-block">
            <input name="id" disabled lay-verify="required" value="#(user.id)" placeholder="请输入" autocomplete="off"
                   class="layui-input" type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">创建时间</label>
        <div class="layui-input-inline">
            <input name="create_time" lay-verify="required" disabled
                   value="#date(user.create_time,'yyyy-MM-dd HH:mm:ss')" placeholder="请输入" autocomplete="off"
                   class="layui-input" type="text">
        </div>
        <div class="layui-form-mid layui-word-aux">请务必填写菜单地址(相对路径)</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input name="name" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input"
                   type="text" value="#(user.name)">
        </div>
        <div class="layui-form-mid layui-word-aux">请务必填写用户名</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-inline">
            <input name="nike_name" placeholder="请输入昵称" autocomplete="off" class="layui-input"
                   type="text" value="#(user.nike_name)">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写昵称(可选)</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input name="password" placeholder="请输入密码" autocomplete="off" class="layui-input"
                   type="text" value="#(user.password)">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写密码</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input name="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input"
                   type="text" value="#(user.email)">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写邮箱</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-inline">
            <input name="phone" placeholder="请输入手机" autocomplete="off" class="layui-input"
                   type="text" value="#(user.phone)">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写手机</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">积分</label>
        <div class="layui-input-inline">
            <input name="point" placeholder="请输入积分" autocomplete="off" class="layui-input"
                   type="text" value="#(user.point)">
        </div>
        <div class="layui-form-mid layui-word-aux">请填写积分</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-inline">
            <select name="user_role_id" >
                #if(userRole!=null)
                <option value="#(userRole.id)">#(userRole.name)</option>
                #end

                #for(role:dmsRoleList)
                #if(userRole!=null)
                #if(role.id != userRole.id)
                <option value="#(role.id)">#(role.name)</option>
                #end
                #else
                <option value="#(role.id)">#(role.name)</option>
                #end
                #end

            </select>
        </div>
        <div class="layui-form-mid layui-word-aux">请选择角色</div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">是否启用</label>
        <div class="layui-input-block">
            #if("on".equals(user.is_open))
            <input name="is_open" type="checkbox" name="switch" lay-skin="switch" lay-text="启用|禁用" checked>
            #else
            <input name="is_open" type="checkbox" name="switch" lay-skin="switch" lay-text="启用|禁用">
            #end

        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="desc" placeholder="请输入内容" class="layui-textarea">#(user.desc)</textarea>
        </div>
    </div>

    <div class="layui-form-item" style="text-align: center">
        <button class="layui-btn" lay-submit="" lay-filter="sendForm">确定修改</button>
    </div>

</form>

<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;

        //注意：parent 是 JS 自带的全局对象，可用于操作父页面
        var parentIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引

        //监听提交
        form.on('submit(sendForm)', function (data) {

            console.log(JSON.stringify(data.field));
            layui.$.ajax({
                type: "post",
                contentType: "application/json;charset=utf-8", // 因为上面是JSON数据
                url: '/admin/user/edit',
                data: JSON.stringify(data.field),
                success: function (data) {

                    if (200 === data.code) {

                        //给父页面刷新
                        parent.layui.table.reload('table');
                        parent.layer.close(parentIndex);
                        parent.layer.msg('修改成功');

                    }

                    console.log(data);
                },
                error: function (data, textStatus, errorThrown) {
                    layer.msg("添加失败");
                    console.log(data);
                }
            });

            return false;
        });
    });
</script>


